package com.agh.szepczynski.magisterka.service.events;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class EventEngine{

	Map<String, Event> events = new HashMap<String, Event>();

	public void addEvent(String token, Event event) {
		events.put(token, event);
	}

	public Event getEvent(String token) {
		return events.get(token);
	}

	public void startEvent(String token) throws Exception {
		try{
			events.get(token).start();
		}catch(Exception e){
			throw new Exception("The thread is probably dead now because its finished",e);
		}
	}

	public void clearEvents() {
		Set<String> keySet = events.keySet();
		for (String token : keySet) {
			Event event = events.get(token);
			// event.stop();
		}
		events.clear(); // cant run thread twice so its necessary
	}



}
